package com.brainyx.sample;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.brainyxlib.BrUtilManager;
import com.brainyxlib.camera.BrCameraManager;
import com.brainyxlib.image.BrImageUtilManager;
import com.brainyxsample.R;

public class CameraActivity extends Activity {

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		
		 if(requestCode == BrCameraManager.PICTURE){
			if(resultCode == RESULT_OK){
				String camerapath= data.getStringExtra("thumbnailurl");
				Bitmap resize = BrImageUtilManager.getInstance().getBitmap(camerapath, false,BrUtilManager.getInstance().getScreenWidth(this),BrUtilManager.getInstance().getScreenHeight(this));
				ImageView image = (ImageView)findViewById(R.id.image);
				image.setImageBitmap(resize);	
			}
			
		}else if(requestCode == BrCameraManager.ALBUM){
			if(resultCode == RESULT_OK){
				String camerapath = data.getStringExtra("thumbnailurl");
				Bitmap resize = BrImageUtilManager.getInstance().getBitmap(camerapath, false,BrUtilManager.getInstance().getScreenWidth(this),BrUtilManager.getInstance().getScreenHeight(this));
				ImageView image = (ImageView)findViewById(R.id.image);
				image.setImageBitmap(resize);	
			}
		}
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.camera);

		init();
	}

	private void init() {
		findViewById(R.id.picture).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				BrCameraManager.getInstance().CallCameraPicture(CameraActivity.this);
			}
		});
		findViewById(R.id.album).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				BrCameraManager.getInstance().CallCameraAlbum(CameraActivity.this);
			}
		});
		
		
	}
}
